﻿using LVYAN.Model.AutoMation;
using LVYAN.Utils;
using System.Collections.Generic;
using System.Linq;
namespace LVYAN.Service
{
    public class AIJQR
    {

        /// <summary>
        /// 设置机器人到本地
        /// </summary>
        /// <returns></returns>
        public void SetRobotModel(RobotModel robotModel)
        {
            JsonToModelService.SetModelByPath($"Data/1_Robot.json", robotModel);
        }
        /// <summary>
        /// 获取设置到本地的机器人
        /// </summary>
        /// <returns></returns>
        public RobotModel GetRobotModel()
        {
            return JsonToModelService.GetModelByPath<RobotModel>($"Data/1_Robot.json");
        }
        /// <summary>
        /// 设置群到本地
        /// </summary>
        /// <returns></returns>
        public void SetRoomModel(RoomModel Model)
        {
            JsonToModelService.SetModelByPath($"Data/2_{Model.Name}/1_Room.json", Model);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RoomName"></param>
        /// <returns></returns>
        public RoomModel GetRoomModel(string RoomName)
        {
            return JsonToModelService.GetModelByPath<RoomModel>($"Data/2_{RoomName}/1_Room.json");
        }
        /// <summary>
        /// 设置群到本地
        /// </summary>
        /// <returns></returns>
        public void SetUserModel(UserModel Model)
        {
            JsonToModelService.SetModelByPath($"Data/2_{Model.RoomName}/2_User_{Model.Name}.json", Model);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RoomName"></param>
        /// <param name="Name"></param>
        /// <returns></returns>
        public UserModel GetUserModel(string RoomName, string Name)
        {
            return JsonToModelService.GetModelByPath<UserModel>($"Data/2_{RoomName}/2_User_{Name}.json");
        }

        /// <summary>
        /// 内容中包含机器人
        /// </summary>
        /// <returns></returns>
        public bool DataExists(List<string> NickNameList, string Data)
        {
            return NickNameList.Where(t => !string.IsNullOrWhiteSpace(t)).Any(t => Data.Contains("@" + t));
        }
        /// <summary>
        /// 内容中包含机器人
        /// </summary>
        /// <returns></returns>
        public string DataRemove(List<string> NickNameList, string Data)
        {
            foreach (var item in NickNameList.Where(t => !string.IsNullOrWhiteSpace(t)))
            {
                Data = Data.Replace("@" + item, "");
                Data = Data.Trim();
            }
            return Data;
        }
    }
}
